$(document).ready(function(){
	var ctx = $("#ctx").val();//获取服务器地址
	
	$('#btn_modifyUrl_clear').click(function(){
		$('#impressionAddress').val('');
		$('#clickAddress').val('');
		$('#visitAddress').val('');
	});
	
	$('#btn_modifyUrl_cannel').click(function(){
		var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
		parent.layer.close(index);//再执行关闭
	});
	
	$('#btn_modifyUrl_save').click(function(){
		var adgroupIds = $('#adgroupIds').val();
		if(adgroupIds==''||adgroupIds==undefined){
			bootbox.alert("系统繁忙！请稍后重试！");
			return false;
		}
		var impressionAddress = $('#impressionAddress').val();
		var clickAddress = $('#clickAddress').val();
		var visitAddress = $('#visitAddress').val();
		bootbox.confirm("投放ID为【"+adgroupIds+"】的所有创意的点击地址修改为【"+clickAddress+"】,曝光地址修改为【"+impressionAddress+"】,到达地址修改为【"+visitAddress+"】吗？", function(ensure){	
			if(ensure){
				$.ajax({
					async: true, 
					traditional: true, 
					type: "POST",
					url:'updateBannerUrl',
					data:{
						"adgroupIds":adgroupIds,
						"clickUrl":clickAddress,
						"impressionUrl":impressionAddress,
						"visitUrl":visitAddress
					},
					success:function(data){
						bootbox.confirm(data+"是否关闭弹窗?", function(ensure){
							if(ensure){
								var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
								parent.layer.close(index);//再执行关闭
							}
						});
					}
				});
			}
		});
	});
	
	//批量修改创意的url
	$("#btn_modify_banner_url").click(function(){
		var checkboxs = $("table tbody .checkboxStyle_change");
		var ids = [];
		if(checkboxs.length>0){
			checkboxs.each(function(){
				var id = parseInt($(this).attr("id"));
				ids.push(id);
			});
			layer.open({
			    type: 2,
				title: '修改创意地址',
				shadeClose: false,
				shade: 0.6,
				minmax:true,
				fix:false,
				closeBtn:0,
				area: ['500px','300px'],
				content: ctx+'/advertiser/main/ad/target/ad-group-alloperator/toupdateBannerUrl?ids='+ids
			});
		}else{
			bootbox.alert("请选择要修改曝光或点击或到达地址的投放！");
			return false;
		}
	});
	
});